#ifndef __XSTRING_H
#define __XSTRING_H

#include "rect.h"
#include "LinkList.h"
	
class CGImage;
enum TXT_ALIGN{TXT_LEFT,TXT_CENTER,TXT_RIGHT};
#define FONT_A           "Arial"
#define FONT_B           "STHeitiTC-Medium"
#define FONT_C           "STHeitiK-Light"

//UILineBreakMode
typedef enum {		
    G_UILineBreakModeWordWrap = 0,            // Wrap at word boundaries
    G_UILineBreakModeCharacterWrap,           // Wrap at character boundaries
    G_UILineBreakModeClip,                    // Simply clip when it hits the end of the rect
    G_UILineBreakModeHeadTruncation,          // Truncate at head of line: "...wxyz". Will truncate multiline text on first line
    G_UILineBreakModeTailTruncation,          // Truncate at tail of line: "abcd...". Will truncate multiline text on last line
    G_UILineBreakModeMiddleTruncation,        // Truncate middle of line:  "ab...yz". Will truncate multiline text in the middle
};

class CXString
{
public:
	CXString();
	~CXString();

	CXString( const CXString& text );
	CXString( const char * text );
	const CXString & operator=( const CXString & text );
	const CXString & operator=( const char * text );
	CXString operator+( const CXString & text );
	CXString operator+( const char * text );
	
	void Format(const char *szFormat, ...);
	void Copy(const char * text);
	void Copy(const CXString& text);
	void CopyNum(int num);
	void CopyNum(double num);
	void Append(const char * text);
	void Append(const CXString& text);
	void AppendNum(int num);
	void AppendNum(double num);
	bool Compare(const char * text);
	bool Compare(const CXString& text);
	double GetValue();
	CXString SubString(int16 location,int16 length);
	const char *Utf8String();
	inline void * GetNSString(){return m_pText;}
	
	void UpperCase();
	void LowerCase();
	void Split(CXList<CXString> *list,CXString param);
	int  Find(CXString param);
	void Insert(CXString text,int pos);
	void Replace(CXString find,CXString replace);
	
	int16 GetLength() const;
	int16 GetTxtPixWidth(const char * fontName, float fontSize);
	int16 GetTxtPixHeight(const char * fontName, float fontSize);
	int16 GetTxtPixHeight(const char * fontName, float fontSize,int16 width,int16 height,int16 mode = G_UILineBreakModeTailTruncation);
	
	void Draw2D(int16 x, int16 y, const char * fontName = FONT_A, float fontSize = 24, RGBVAL color = 0xffffff,int16 width = -1, int16 height = -1, int16 mode = G_UILineBreakModeTailTruncation);
	void Draw2D(int16 x, int16 y, TXT_ALIGN align = TXT_LEFT, const char * fontName = FONT_A, float fontSize = 24, RGBVAL color = 0xffffff);
private:
	void ClearTexture();
private:
	void * m_pText;
	void * m_pTexture;
	int16  m_width;
	int16  m_height;
    int16  m_FontSize;
    
};

#endif // __XSTRING_H